package com.atguigu.jxc.controller;

import com.alibaba.fastjson.JSON;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.entity.*;
import com.atguigu.jxc.service.StockService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping
public class StockController {
    @Autowired
    private StockService stockService;
    /**
     * http://localhost:8080/damageListGoods/save?damageNumber=BS1605766644460（报损单号,前端生成）
     * 请求参数：DamageList damageList, String damageListGoodsStr
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：ServiceVO
     */
    @PostMapping("damageListGoods/save")
    public ServiceVO saveDamageListGoods(DamageList damageList, String damageListGoodsStr){
        try {
            List<DamageListGoods> list = JSON.parseArray(damageListGoodsStr, DamageListGoods.class);
            stockService.saveDamageListGoods(damageList,list);
        } catch (Exception e) {
            e.printStackTrace();
            return new ServiceVO(200,"请求失败");
        }
        return new ServiceVO(100,"请求成功");
    }
    /**
     * http://localhost:8080/overflowListGoods/save?overflowNumber=BY1605767033015（报溢单号）
     * 请求参数：OverflowList overflowList, String overflowListGoodsStr
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：ServiceVO
     */
    @PostMapping("overflowListGoods/save")
    public ServiceVO saveOverflowListGoods(OverflowList overflowList, String overflowListGoodsStr){
        try {
            List<OverflowListGoods> list = JSON.parseArray(overflowListGoodsStr, OverflowListGoods.class);
            stockService.saveOverflowListGoods(overflowList,list);
        } catch (Exception e) {
            e.printStackTrace();
            return new ServiceVO(200,"请求失败");
        }
        return new ServiceVO(100,"请求成功");
    }
    /**
     * 请求URL：http://localhost:8080/goods/listAlarm
     * 请求参数：无
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：Map<String,Object>
     */
    @PostMapping("goods/listAlarm")
    public Map<String,Object> listAlarm(){
        return stockService.listAlarm();
    }
    /**
     * 请求URL：http://localhost:8080/damageListGoods/list
     * 请求参数：String  sTime（开始时间）, String  eTime（结束时间）
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：Map<String,Object>
     */
    @PostMapping("damageListGoods/list")
    public Map<String,Object> damageListGoodsList(String sTime, String  eTime){
        Map<String, Object> map = stockService.damageListGoodsList(sTime, eTime);
        return map;
    }
    /**
     * 请求URL：http://localhost:8080/damageListGoods/goodsList
     * 请求参数：Integer damageListId（报损单Id）
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：Map<String,Object>
     */
    @PostMapping("damageListGoods/goodsList")
    public Map<String,Object> damageGoodsList(Integer damageListId){
        return stockService.damageGoodsList(damageListId);
    }
    /**
     * 请求URL：http://localhost:8080/overflowListGoods/list
     * 请求参数：String  sTime（开始时间）, String  eTime（结束时间）
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：Map<String,Object>
     */
    @PostMapping("overflowListGoods/list")
    public Map<String,Object> overflowList(String sTime, String  eTime){
        Map<String, Object> map = stockService.overflowList(sTime, eTime);
        return map;
    }
    /**
     * 请求URL：http://localhost:8080/overflowListGoods/goodsList
     * 请求参数：Integer overflowListId
     * 请求方式：POST
     * 返回值类型：JSON
     * 返回值：Map<String,Object>
     */
    @PostMapping("overflowListGoods/goodsList")
    public Map<String,Object> overflowListGoodsList(Integer overflowListId){
        return stockService.overflowListGoodsList(overflowListId);
    }

}
